'use strict';
const Controller = require('egg').Controller;
const { v4: uuidv4 } = require('uuid');

class AdminController extends Controller {
  async getSchools() {
    const { ctx, app } = this;
    const { page, limit } = ctx.query;
    const result = await ctx.service.admin.getSchools(page, limit);
    ctx.body = result;
  }

  async getShops() {
    const { ctx, app } = this;
    const { page, limit } = ctx.query;
    const result = await ctx.service.admin.getShops(page, limit);
    ctx.body = result;
  }

  async getAreas() {
    const { ctx, app } = this;
    const { page, limit } = ctx.query;
    const result = await ctx.service.admin.getAreas(page, limit);
    ctx.body = result;
  }

  async addSchool() {
    const { ctx, app } = this;
    const data = ctx.request.body;
    const result = await ctx.service.admin.addSchool(data);
    ctx.body = result;
  }

  async addShop() {
    const { ctx, app } = this;
    const data = ctx.request.body;
    const result = await ctx.service.admin.addShop(data);
    ctx.body = result;
  }

  async addArea() {
    const { ctx, app } = this;
    const data = ctx.request.body;
    const result = await ctx.service.admin.addArea(data);
    ctx.body = result;
  }

  async deleteSchool() {
    const { ctx, app } = this;
    const { school_id } = ctx.params;
    const result = await ctx.service.admin.deleteSchool(school_id);
    ctx.body = result;
  }

  async deleteShop() {
    const { ctx, app } = this;
    const { shop_id } = ctx.params;
    const result = await ctx.service.admin.deleteShop(shop_id);
    ctx.body = result;
  }

  async deleteArea() {
    const { ctx, app } = this;
    const { area_id } = ctx.params;
    const result = await ctx.service.admin.deleteArea(area_id);
    ctx.body = result;
  }

  async putSchool() {
    const { ctx, app } = this;
    const data = ctx.request.body;
    const { school_id } = ctx.params;
    const result = await ctx.service.admin.putSchool(school_id,data);
    ctx.body = result;
  }

  async putShop() {
    const { ctx, app } = this;
    const data = ctx.request.body;
    const { shop_id } = ctx.params;
    const result = await ctx.service.admin.putSchool(shop_id,data);
    ctx.body = result;
  }

  async putArea() {
    const { ctx, app } = this;
    const data = ctx.request.body;
    const { area_id } = ctx.params;
    const result = await ctx.service.admin.putSchool(area_id,data);
    ctx.body = result;
  }

  async getSimpleOrders(){
    const { ctx, app } = this;
    const { page, limit } = ctx.query;
    const result = await ctx.service.admin.getSimpleOrders(page, limit);
    ctx.body = result;
  }
  
  async getOrder(){
    const { ctx, app } = this;
    const result = await ctx.service.admin.getOrder();
    ctx.body = result;
  }
}

module.exports = AdminController;